/**
 * Copyright 2011 Joe Choi, All rights reserved.
 */
package tao.time;

/**
 * The AbstractTime class is designed as basic implementation of Time interface
 * 
 * @author Joe Choi
 * @version 1.0.0
 */
public abstract class AbstractTime implements Time{
	@Override
	public boolean equals(Object obj) {
		if(! (obj instanceof Time)) return(false);
		Time other = (Time) obj;
		return(this.scalar() == other.scalar());
	}

	@Override
	public int hashCode() {
		return((int) scalar());
	}
	
	@Override
	public boolean after(Time otherTime) {
		return(compareTo(otherTime) > 0);
	}

	@Override
	public boolean before(Time otherTime) {
		return(compareTo(otherTime) < 0);
	}

	@Override
	public int compareTo(Time otherTime) {
		long diff = Math.abs(this.scalar() - otherTime.scalar());
		if(diff > 0) return(1);
		else if(diff == 0) return(0);
		else return(-1);
	}	
}
